package test.patterns;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorDemo {

	public static void main(String[] args) {

		IteratorItem i1 = new IteratorItem("spaghetti", 7.50f);
		IteratorItem i2 = new IteratorItem("hamburger", 6.00f);
		IteratorItem i3 = new IteratorItem("chicken sandwich", 6.50f);

		IteratorMenu menu = new IteratorMenu();
		menu.addItem(i1);
		menu.addItem(i2);
		menu.addItem(i3);

		System.out.println("Displaying Menu:");
		Iterator<IteratorItem> iterator = menu.iterator();
		
		for (IteratorItem itemFE : menu ) {
			System.out.println(itemFE);
		}
		
		while (iterator.hasNext()) {
			IteratorItem item = iterator.next();
			System.out.println(item);
		}

		System.out.println("\nRemoving last item returned");
		iterator.remove();

		System.out.println("\nDisplaying Menu:");
		iterator = menu.iterator();
		while (iterator.hasNext()) {
			IteratorItem item = iterator.next();
			System.out.println(item);
		}

		//Egen ide .... :-)
		System.out.println("for each over list");
		List<IteratorItem> list = new ArrayList<IteratorItem>();
		for (IteratorItem it: list) {
			System.out.println(it);
		}
	}

}